#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<vector<int>> fourSum(vector<int>& nums, int target) {
    vector<vector<int>> ret;

    sort(nums.begin(), nums.end());
    for (int i = 0; i < nums.size();)
    {
        for (int j = i + 1; j < nums.size();)
        {
            int left = j + 1, right = nums.size()-1;
            long long num = (long long)target - nums[i] - nums[j];
            while (left < right)
            {
                if (nums[left] + nums[right] < num)
                    left++;
                else if (nums[left] + nums[right] > num)
                    right--;
                else
                {
                    ret.push_back({ nums[i], nums[j], nums[left], nums[right] });
                    left++;
                    right--;
                    while (left < right && nums[left - 1] == nums[left]) left++;
                    while (left < right && nums[right] == nums[right+1]) right--;
                }
            }
            j++;
            while (j < nums.size() && nums[j - 1] == nums[j]) j++;
        }
        i++;
        while (i < nums.size() && nums[i - 1] == nums[i]) i++;
    }
    return ret;
}

int main()
{
    vector<int> v = { 1000000000,1000000000,1000000000,1000000000 };
    vector<vector<int>> vv = fourSum(v, -294967296);
    for (int i = 0; i < vv.size(); i++)
    {
        for (int j = 0; j < vv[i].size(); j++)
        {
            cout << vv[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}